// pages/home/home.js
// import { getModlues } from './service.js'
import * as service from './service.js'
Page({

  /**
   * 页面的初始数据22222
   */
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 500,
    modules:[],
    banners: {},
     navs:[{id:1, title: '豆瓣金典', icon:"data:image/svg+xml;charset=utf-8,%3Csvg width='22' height='22' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cdefs%3E%3Cpath id='a' d='M0 .151H17.53V22H0z'/%3E%3C/defs%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg transform='translate(0 -.151)'%3E%3Cmask id='b' fill='%23fff'%3E%3Cuse xlink:href='%23a'/%3E%3C/mask%3E%3Cpath d='M16.659 22H.87a.87.87 0 01-.87-.87V1.021c0-.48.389-.87.87-.87h15.787c.48 0 .87.39.87.87v20.11c0 .48-.39.87-.87.87' fill='%2344883E' mask='url(https://img1.doubanio.com%23b)'/%3E%3C/g%3E%3Cpath d='M21.96 1.108v19.634a1.107 1.107 0 01-2.216 0V1.108a1.108 1.108 0 012.215 0' fill='%238FB88B'/%3E%3C/g%3E%3C/svg%3E"}, {id:1, title: '家居生活', icon:"data:image/svg+xml;charset=utf-8,%3Csvg width='22' height='22' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cdefs%3E%3Cpath id='a' d='M0 .151H17.53V22H0z'/%3E%3C/defs%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg transform='translate(0 -.151)'%3E%3Cmask id='b' fill='%23fff'%3E%3Cuse xlink:href='%23a'/%3E%3C/mask%3E%3Cpath d='M16.659 22H.87a.87.87 0 01-.87-.87V1.021c0-.48.389-.87.87-.87h15.787c.48 0 .87.39.87.87v20.11c0 .48-.39.87-.87.87' fill='%2344883E' mask='url(https://img1.doubanio.com%23b)'/%3E%3C/g%3E%3Cpath d='M21.96 1.108v19.634a1.107 1.107 0 01-2.216 0V1.108a1.108 1.108 0 012.215 0' fill='%238FB88B'/%3E%3C/g%3E%3C/svg%3E"}, {id:1, title: '外出旅行', icon:"data:image/svg+xml;charset=utf-8,%3Csvg width='22' height='22' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cdefs%3E%3Cpath id='a' d='M0 .151H17.53V22H0z'/%3E%3C/defs%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg transform='translate(0 -.151)'%3E%3Cmask id='b' fill='%23fff'%3E%3Cuse xlink:href='%23a'/%3E%3C/mask%3E%3Cpath d='M16.659 22H.87a.87.87 0 01-.87-.87V1.021c0-.48.389-.87.87-.87h15.787c.48 0 .87.39.87.87v20.11c0 .48-.39.87-.87.87' fill='%2344883E' mask='url(https://img1.doubanio.com%23b)'/%3E%3C/g%3E%3Cpath d='M21.96 1.108v19.634a1.107 1.107 0 01-2.216 0V1.108a1.108 1.108 0 012.215 0' fill='%238FB88B'/%3E%3C/g%3E%3C/svg%3E"}, {id:1, title: '文具小屋', icon:"data:image/svg+xml;charset=utf-8,%3Csvg width='22' height='22' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cdefs%3E%3Cpath id='a' d='M0 .151H17.53V22H0z'/%3E%3C/defs%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg transform='translate(0 -.151)'%3E%3Cmask id='b' fill='%23fff'%3E%3Cuse xlink:href='%23a'/%3E%3C/mask%3E%3Cpath d='M16.659 22H.87a.87.87 0 01-.87-.87V1.021c0-.48.389-.87.87-.87h15.787c.48 0 .87.39.87.87v20.11c0 .48-.39.87-.87.87' fill='%2344883E' mask='url(https://img1.doubanio.com%23b)'/%3E%3C/g%3E%3Cpath d='M21.96 1.108v19.634a1.107 1.107 0 01-2.216 0V1.108a1.108 1.108 0 012.215 0' fill='%238FB88B'/%3E%3C/g%3E%3C/svg%3E"}],
  },
    // getModlues(){
    //   wx.request({
    //     url: 'https://market.douban.com/api/v2/market/home/modules?ivk_sa=1024320u', 
    //     data: {},
    //     header: {
    //       'content-type': 'application/json' // 默认值
    //     },
    //     success (res) {
    //       console.log(res)
    //     }
    //   })
    // },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    service.getModlues((res)=>{
      // 解构取 modules
      const { modules } = res.data
      let result = modules.find(mod=>mod.key  === "market_banner")
      if(result){
        this.setData({
          banners: result
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    console.log("onUnload")
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("onPullDownRefreshonPullDownRefresh")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})